package Actions;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.ResourceBundle;

import util.reflection.Reflection;
import view.ViewController;

public class ActionFactory {

	private static HashMap<String, AbstractActionPerformed> supportedActions;

	/**
	 * Uses reflection to map action strings to the class that represents them
	 */
	public static void loadActions() {
		ResourceBundle actions = ResourceBundle.getBundle("resources.action");
		supportedActions = new HashMap<String, AbstractActionPerformed>();
		for (String key : actions.keySet()) {
			supportedActions.put(key, (AbstractActionPerformed) Reflection
					.createInstance(actions.getString(key)));
		}
	}

	/**
	 * Perform action corresponding the JUnit object. 
	 * @param action String associated with class name in resource file. 
	 * @param listener ActionListener for support of new objects created
	 */
	public static void createAction(String action, ViewController listener, ActionEvent e)
	{
		Reflection.callMethod(supportedActions.get(action), "action", listener, e);
	}
	
}
